package engine.core
{
	import flash.display.*;
	import flash.system.*;
	import flash.utils.*;
	
	public class RxUtilities
	{
		public static const s_regExpFloat:RegExp = /[\+\-]?\d*\.?\d*[eE]?[\+\-]?\d*""[\+\-]?\d*\.?\d*[eE]?[\+\-]?\d*/;
		public static const s_regExpFloat2:RegExp = new RegExp("\\s*(" + s_regExpFloat.source + ")\\s*,?\\s*(" + s_regExpFloat.source + ")");
		public static const s_regExpFloat3:RegExp = new RegExp("\\s*(" + s_regExpFloat.source + ")\\s*,?\\s*(" + s_regExpFloat.source + ")\\s*,?\\s*(" + s_regExpFloat.source + ")");
		public static const s_regExpFloat4:RegExp = new RegExp("\\s*(" + s_regExpFloat.source + ")\\s*,?\\s*(" + s_regExpFloat.source + ")\\s*,?\\s*(" + s_regExpFloat.source + ")\\s*,?\\s*(" + s_regExpFloat.source + ")");

		public function RxUtilities()
		{
		}
		
		public static function DeleteObject(obj:Object) : void
		{
			while (!IsObjectEmpty(obj))
			{
				
				for (var key:String in obj)
				{
					
					obj[key] = null;
					delete obj[key];
				}
			}
		}
		
		public static function IsObjectEmpty(obj:Object) : Boolean
		{
			var IsEmpty:Boolean = true;
			for (var key:String in obj)
			{
				
				IsEmpty = false;
				break;
			}
			
			return IsEmpty;
		}
		
		public static function ConvertToReadableTime(time:int) : String
		{
			var _loc_9:String = null;
			var _loc_10:String = null;
			var _loc_2:* = time / (60 * 60 * 1000);
			time = time - _loc_2 * (60 * 60 * 1000);
			var _loc_3:* = time / (60 * 1000);
			time = time - _loc_3 * (60 * 1000);
			var _loc_4:* = time / 1000;
			time = time - _loc_4 * 1000;
			var _loc_5:* = time;
			var _loc_6:* = time.toString();
			if (time.toString().length < 3)
			{
				_loc_6 = "0" + _loc_6;
			}
			if (_loc_6.length < 3)
			{
				_loc_6 = "0" + _loc_6;
			}
			var _loc_7:* = _loc_6 + "ms";
			var _loc_8:* = _loc_4.toString();
			if (_loc_4.toString().length < 2)
			{
				_loc_8 = "0" + _loc_8;
			}
			_loc_7 = _loc_8 + "s " + _loc_7;
			if (_loc_3 > 0 || _loc_2 > 0)
			{
				_loc_9 = _loc_3.toString();
				if (_loc_9.length < 2)
				{
					_loc_9 = "0" + _loc_9;
				}
				_loc_7 = _loc_9 + "m " + _loc_7;
			}
			if (_loc_2 > 0)
			{
				_loc_10 = _loc_2.toString();
				_loc_7 = _loc_10 + "h " + _loc_7;
			}
			
			return _loc_7;
		}
		
		public static function NormalizeURL(url:String) : String
		{
			var index:int = 0;
			if (url == null)
			{
				return null;
			}
			
			url = url.toLowerCase();
			url = url.replace(/\\\"""\\/g, "/");
			var arr:Array = url.split("/");
			var bol:Boolean = false;
			while (!bol)
			{
				
				index = arr.indexOf("..");
				if (index == -1)
				{
					bol = true;
					continue;
				}
				arr.splice((index - 1), 2);
			}
			url = arr.join("/");
			
			return url;
		}
		
		public static function MergePath(info:String, url:String) : String
		{
			if (url.indexOf("/") == 0)
			{
				return url.slice(1);
			}
			if (url.indexOf("\\") == 0)
			{
				return url.slice(1);
			}
			if (info == null)
			{
				return url;
			}
			var _loc_3:* = info.lastIndexOf("/");
			var _loc_4:* = info.lastIndexOf("\\");
			var _loc_5:* = _loc_3 > _loc_4 ? (_loc_3) : (_loc_4);
			var str:String = "";
			if (_loc_5 > 0)
			{
				str = info.substring(0, (_loc_5 + 1));
			}
			str = str + url;
			
			return str;
		}
		
		public static function scvt(time:Number, param2:uint) : String
		{
			var _loc_3:String = null;
			var _loc_4:* = Math.abs(time);
			if (Math.abs(time) < 1024)
			{
				_loc_3 = "B";
			}
			else if (_loc_4 < 1024 * 1024)
			{
				_loc_3 = "KB";
				time = time * (1 / 1024);
			}
			else if (_loc_4 < 1024 * 1024 * 1024)
			{
				_loc_3 = "MB";
				time = time * (1 / (1024 * 1024));
			}
			else
			{
				_loc_3 = "GB";
				time = time * (1 / (1024 * 1024 * 1024));
			}
			var _loc_5:* = time.toFixed(param2) + " " + _loc_3;
			return time.toFixed(param2) + " " + _loc_3;
		}
		
		public static function ForceGarbageCollection() : void
		{
			System.pauseForGCIfCollectionImminent(0);
		}
		
		public static function ConvertToReadableUTCDate(time:Date) : String
		{
			var _loc_2:* = time.getUTCFullYear().toString();
			var _loc_3:* = (time.getUTCMonth() + 1).toString();
			var _loc_4:* = time.getUTCDate().toString();
			var _loc_5:* = time.getUTCHours().toString();
			var _loc_6:* = time.getUTCMinutes().toString();
			var _loc_7:* = time.getUTCSeconds().toString();
			var _loc_8:* = time.getUTCMilliseconds().toString();
			if (_loc_3.length < 2)
			{
				_loc_3 = "0" + _loc_3;
			}
			if (_loc_4.length < 2)
			{
				_loc_4 = "0" + _loc_4;
			}
			if (_loc_5.length < 2)
			{
				_loc_5 = "0" + _loc_5;
			}
			if (_loc_6.length < 2)
			{
				_loc_6 = "0" + _loc_6;
			}
			if (_loc_7.length < 2)
			{
				_loc_7 = "0" + _loc_7;
			}
			if (_loc_8.length < 3)
			{
				_loc_8 = "0" + _loc_8;
			}
			if (_loc_8.length < 3)
			{
				_loc_8 = "0" + _loc_8;
			}
			
			return _loc_2 + "-" + _loc_3 + "-" + _loc_4 + " " + _loc_5 + ":" + _loc_6 + ":" + _loc_7 + "." + _loc_8;
		}
		
		public static function DeleteVector(param1:Object) : void
		{
			var _loc_3:int = 0;
			var _loc_2:* = new Vector.<Object>(param1);
			if (_loc_2 != null)
			{
				_loc_3 = 0;
				while (_loc_3 < _loc_2.length)
				{
					
					_loc_2[_loc_3] = null;
					_loc_3++;
				}
				_loc_2.length = 0;
			}
		}
		
		public static function CleanupWhitespaces(param1:String) : String
		{
			var _loc_2:String = null;
			_loc_2 = param1.replace(/^\s+""^\s+/, "");
			_loc_2 = _loc_2.replace(/\s+$""\s+$/, "");
			_loc_2 = _loc_2.replace(/\s+""\s+/g, " ");
			return _loc_2;
		}
		
		public static function CountObjectElements(param1:Object) : uint
		{
			var _loc_3:String = null;
			var _loc_2:uint = 0;
			for (_loc_3 in param1)
			{
				
				_loc_2 = _loc_2 + 1;
			}
			return _loc_2;
		}
		
		public static function DeleteArray(param1:Array) : void
		{
			var _loc_2:int = 0;
			_loc_2 = 0;
			while (_loc_2 < param1.length)
			{
				
				param1[_loc_2] = null;
				_loc_2++;
			}
			param1.length = 0;
			DeleteObject(param1);

		}
		
		public static function GetRandomIntegerInRange(param1:int, param2:int) : int
		{
			return Math.floor(param1 + Math.random() * (param2 - param1 + 1));
		}
		
		public static function FillVectorWithRandomUniqueIntegers(param1:Vector.<int>) : void
		{
			var _loc_5:int = 0;
			var _loc_6:int = 0;
			var _loc_2:* = param1.length;
			var _loc_3:int = 0;
			while (_loc_3 < _loc_2)
			{
				
				param1[_loc_3] = _loc_3;
				_loc_3++;
			}
			var _loc_4:* = _loc_2 - 1;
			while (_loc_4 > 0)
			{
				
				_loc_5 = int(Math.random() * _loc_4);
				_loc_6 = param1[_loc_4];
				param1[_loc_4] = param1[_loc_5];
				param1[_loc_5] = _loc_6;
				_loc_4 = _loc_4 - 1;
			}
		}
		
		public static function Fmod(param1:Number, param2:Number) : Number
		{
			return param1 - param2 * Math.floor(param1 / param2);
		}
	}
}